package com.hz.ruoyifarmbase.farm.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.hz.ruoyifarmbase.farm.domain.AgrBaseOperate;
import com.hz.ruoyifarmbase.farm.service.IAgrBaseOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 作物种植操作Controller
 *
 * @author zjk
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/operate")
@CrossOrigin(origins = "*")
public class AgrBaseOperateController extends BaseController
{
    @Autowired
    private IAgrBaseOperateService agrBaseOperateService;

    /**
     * 查询作物种植操作列表
     */
    @RequiresPermissions("farm:operate:list")
    @GetMapping("/list")
    public TableDataInfo list(AgrBaseOperate agrBaseOperate)
    {
        startPage();
        List<AgrBaseOperate> list = agrBaseOperateService.selectAgrBaseOperateList(agrBaseOperate);
        return getDataTable(list);
    }

    /**
     * 导出作物种植操作列表
     */
    @RequiresPermissions("farm:operate:export")
    @Log(title = "作物种植操作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgrBaseOperate agrBaseOperate)
    {
        List<AgrBaseOperate> list = agrBaseOperateService.selectAgrBaseOperateList(agrBaseOperate);
        ExcelUtil<AgrBaseOperate> util = new ExcelUtil<AgrBaseOperate>(AgrBaseOperate.class);
        util.exportExcel(response, list, "作物种植操作数据");
    }

    /**
     * 获取作物种植操作详细信息
     */
    @RequiresPermissions("farm:operate:query")
    @GetMapping(value = "/{operateId}")
    public AjaxResult getInfo(@PathVariable("operateId") Long operateId)
    {
        return success(agrBaseOperateService.selectAgrBaseOperateByOperateId(operateId));
    }

    /**
     * 新增作物种植操作
     */
    @RequiresPermissions("farm:operate:add")
    @Log(title = "作物种植操作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgrBaseOperate agrBaseOperate)
    {
        return toAjax(agrBaseOperateService.insertAgrBaseOperate(agrBaseOperate));
    }

    /**
     * 修改作物种植操作
     */
    @RequiresPermissions("farm:operate:edit")
    @Log(title = "作物种植操作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgrBaseOperate agrBaseOperate)
    {
        return toAjax(agrBaseOperateService.updateAgrBaseOperate(agrBaseOperate));
    }

    /**
     * 删除作物种植操作
     */
    @RequiresPermissions("farm:operate:remove")
    @Log(title = "作物种植操作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operateIds}")
    public AjaxResult remove(@PathVariable Long[] operateIds)
    {
        return toAjax(agrBaseOperateService.deleteAgrBaseOperateByOperateIds(operateIds));
    }


    @GetMapping("/getProcessByBatchId/{batchId}")
    public AjaxResult getProcessByBatchId(@PathVariable String batchId)
    {
        System.out.println(batchId);
        return success(agrBaseOperateService.getProcessByBatchId(Long.valueOf(batchId)));
    }
}
